package com.laker.autotest.webui.testcase.example;

import com.laker.autotest.webui.core.BasePageTest;
import com.laker.autotest.webui.page.csdn.CsdnHomePage;
import com.laker.autotest.webui.page.csdn.CsdnLoginPage;
import com.laker.autotest.webui.page.csdn.CsdnSearchPage;
import com.laker.autotest.webui.page.csdn.CsdnUserHomePage;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

/**
 * <pre>
 * {@code @Test(priority = 1)}中的priority表示执行顺序，数字越小越先执行
 * </pre>
 */
public class CsdnPageTest extends BasePageTest {
    @Test(enabled = false, priority = 1)
    public void 从首页测试搜索() {
        CsdnHomePage csdnHomePage = new CsdnHomePage(page);
        CsdnSearchPage searchPage = csdnHomePage.search("lakernote");
        searchPage.clickUserTab();
        searchPage.search("lakernote");
        String searchResult = searchPage.getSearchResult();
        Assert.assertTrue(searchResult.contains("lakernote"));
    }

    @Test(enabled = false, priority = 2)
    public void 从搜索页测试搜索() {
        CsdnSearchPage searchPage = new CsdnSearchPage(page);
        searchPage.clickUserTab();
        searchPage.search("lakernote");
        String searchResult = searchPage.getSearchResult();
        Assert.assertTrue(searchResult.contains("lakernote"));
    }

    @Test(enabled = false, dataProvider = "loginTestData", priority = 3)
    public void login(String user, String pwd) {
        CsdnLoginPage csdnLoginPage = new CsdnLoginPage(page);
        String result = csdnLoginPage.login(user, pwd);
        Assert.assertEquals(result, "长时间未修改密码，请通过\"忘记密码\"修改密码后登录");
    }

    @DataProvider(name = "loginTestData")
    public Object[][] loginTestData() {
        return new Object[][]{
                {"user1", "user1pwd"},
                {"user2", "user2pwd"},
                {"user3", "user3pwd"}
        };
    }

    @Test(enabled = false)
    public void userHome() {
        CsdnUserHomePage csdnUserHomePage = new CsdnUserHomePage(page);
        csdnUserHomePage.list();
    }
}